// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © julzen2

//@version=5
indicator("ATR Channels", overlay=true)

// === INPUTS ===
PeriodsATR   = input.int(18, title="ATR Period")
MA_Periods   = input.int(49, title="MA Period")
MA_type_opt  = input.string("SMA", title="MA Type", options=["SMA", "EMA", "WMA", "VWMA"])
Mult_Factor1 = input.float(1.6, title="Multiplier 1")
Mult_Factor2 = input.float(3.2, title="Multiplier 2")
Mult_Factor3 = input.float(4.8, title="Multiplier 3")

// === HELPER FUNCTIONS ===
get_ma(src, len) =>    MA_type_opt == "SMA"  ? ta.sma(src, len) :    MA_type_opt == "EMA"  ? ta.ema(src, len) :    MA_type_opt == "WMA"  ? ta.wma(src, len) :    MA_type_opt == "VWMA" ? ta.vwma(src, len) :    na

// === CORE CALCULATIONS ===
src = hlc3
atr = ta.atr(PeriodsATR)
ma = get_ma(src, MA_Periods)

// === CHANNEL LEVELS ===
ch1_upper = ma + Mult_Factor1 * atr
ch1_lower = ma - Mult_Factor1 * atr
ch2_upper = ma + Mult_Factor2 * atr
ch2_lower = ma - Mult_Factor2 * atr
ch3_upper = ma + Mult_Factor3 * atr
ch3_lower = ma - Mult_Factor3 * atr

// === PLOT ===
// Only the outermost bands are visible (like in your MQL4 indicator)
plot(ch3_upper, title="ATRu3", color=color.purple, linewidth=1)
plot(ch3_lower, title="ATRd3", color=color.purple, linewidth=1)

// Optional: Uncomment below to show inner bands too
//plot(ch1_upper, title="ATRu1", color=color.aqua, linewidth=1)
//plot(ch1_lower, title="ATRd1", color=color.aqua, linewidth=1)
//plot(ch2_upper, title="ATRu2", color=color.blue, linewidth=1)
//plot(ch2_lower, title="ATRd2", color=color.blue, linewidth=1)

// Optional: Plot the moving average line
//plot(ma, title="Moving Average", color=color.green)
